/**
 * https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/
 * 算法导论中的最大子数组问题
 * 可以用分治,也可以用动态规划
 */
package dataStructure.Test121买卖股票的最佳时机;

/**
 * 贪心
 */
public class Solution3 {
    public int maxProfit(int[] prices) {
        int low = Integer.MAX_VALUE;
        int result = 0;
        for (int i = 0; i < prices.length; i++) {
            low = Math.min(low, prices[i]);
            result = Math.max(result, prices[i] - low);
        }
        return result;
    }
}
